<?php
namespace app\wechat\controller;

class Distribution extends WCommon
{
    public function index()
    {
        return view();
    }

    public function getData()
    {
        $get_type = intval(@$_GET["type"]);/*0:维修,2:拖车,4:保养,6:购车,8:保险*/
        $get_lng = floatval(@$_GET["lng"]);
        $get_lat = floatval(@$_GET["lat"]);

        /*
        http://restapi.amap.com/v3/geocode/regeo?key=23b48012ac55a9b14bc9400c94c261d9&location=112.935696,28.232281&poitype=&radius=1000&extensions=base&batch=false&roadlevel=0
        {"status":"1","info":"OK","infocode":"10000","regeocode":{"formatted_address":"湖南省长沙市岳麓区望岳街道杜鹃路548号八方小区(观沙路)","addressComponent":{"country":"中国","province":"湖南省","city":"长沙市","citycode":"0731","district":"岳麓区","adcode":"430104","township":"望岳街道","towncode":"430104009000","neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"streetNumber":{"street":"杜鹃路","number":"548号","location":"112.93565,28.2323283","direction":"西北","distance":"6.92694"},"businessAreas":[{"location":"112.95052523333335,28.235600011111117","name":"观沙岭","id":"430104"},{"location":"112.92231154077258,28.221183643776815","name":"望岳","id":"430104"},{"location":"112.92750420454541,28.220168318181813","name":"咸嘉新村","id":"430104"}]}}}
        */

        if( @$_GET["c"]=="address" ){
            $tmpUrl = "http://restapi.amap.com/v3/geocode/regeo?key=23b48012ac55a9b14bc9400c94c261d9&location=".$get_lng.",".$get_lat."&poitype=&radius=1000&extensions=base&batch=false&roadlevel=0";
            echo file_get_contents($tmpUrl);
            exit();
        }


        if( !$get_lng || !$get_lat ){
            exit('{"code":0,"msg":"缺少经纬度数据"}');
        }

        //开始模拟测试数据
        $get_lng_begin = ($get_lng - 0.01)*100000;
        $get_lng_end = ($get_lng + 0.01)*100000;
        $get_lat_begin = ($get_lat - 0.01)*100000;
        $get_lat_end = ($get_lat + 0.01)*100000;
        $tmpHead[0] = "/view/static/images/1.jpg";
        $tmpHead[1] = "/view/static/images/dx_12.png";
        $tmpHead[2] = "/view/static/images/home_img_03.jpg";
        $tmpHead[3] = "/view/static/images/message_showimg01.png";
        $tmpHead[4] = "/view/static/images/message_showimg02.png";
        $tmpHead[5] = "/view/static/images/systemmessage_img_03.png";
        //随机几个
        $rand_num = rand(2,8);
        $tmpData = "";
        for($i=0;$i<$rand_num;$i++){
            $tmpID = rand(1,16);
            $tmpLat = rand($get_lat_begin,$get_lat_end)/100000;
            $tmpLon = rand($get_lng_begin,$get_lng_end)/100000;
            $tmpCover = $tmpHead[rand(0,count($tmpHead)-1)];
            $tmpData .= '{"id":'.$tmpID.',"repair_name":"测试商家名'.$tmpID.'","address":"测试商家地址'.$tmpID.'","lat":'.$tmpLat.',"lon":'.$tmpLon.',"cover":"'.$tmpCover.'"},';
        }
        $tmpData = substr($tmpData,0,strlen($tmpData)-1);
        $tmpJson = '{"code":1,"data":['.$tmpData.']}';

        echo $tmpJson;
        exit();
    }
}
